<%inherit file="base.html"/>

<%def name="head()">
<script>
    function deletePolicy(policy_id)
    {
        if(confirm("确认删除吗？"))
        {
            params = {policy_id: policy_id, _xsrf: '${handler.xsrf_token}'};
            $.post("/policy/delete", params, function (data) {
                if (data.code > 0) {
                    alert(data.msg)
                    return false;
                }
                else {
                    window.location.href = "/policy";
                }
            }, "json");
        }
    }

    function activatePolicy(policy_id)
    {
        if(confirm("同一时间只有一台服务器能处于活动状态,确认激活策略服务器吗？"))
        {
            window.location.href = "/policy/activate?policy_id="+policy_id;
        }
    }
</script>
</%def>

<%def name="body()">
<section class="content">
    <div class="box box-primary">
        <div class="box-header">
            <i class="fa fa-sitemap"></i>
            <h3 class="box-title">策略服务器列表</h3>
        </div>
        <div class="box-body">
            <div class="container">
                % if permit.match(current_user.username,'/policy/add'):
                <div class="pull-right bottom10">
                     <a href="/policy/add" class="btn btn-sm btn-default">增加策略服务器信息</a>
                </div>
                % endif

                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>策略服务器IP</th>
                            <th>策略服务器认证端口</th>
                            <th>策略服务器记账端口</th>
                            <th>状态</th>
                            <th>共享密钥</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        % for policy_server in policy_server_list:
                            <tr>
                                <td>${policy_server.policy_server_ip}</td>
                                <td>${policy_server.policy_auth_port}</td>
                                <td>${policy_server.policy_acct_port}</td>
                                <td>${policy_status[policy_server.status]}</td>
                                <td>${policy_server.secret}</td>
                                <td>
                                    % if permit.match(current_user.username,'/policy/update'):
                                    <a class="opt-btn btn-default" href="/policy/update?policy_id=${policy_server.id}">修改</a>
                                    % endif
                                    % if permit.match(current_user.username,'/policy/delete'):
                                    <a class="opt-btn btn-default" href="javascript:deletePolicy('${policy_server.id}')">删除</a>
                                    % endif
                                    % if permit.match(current_user.username,'/policy/activate'):
                                    <a class="opt-btn btn-default" href="javascript:activatePolicy('${policy_server.id}')">激活</a>
                                    % endif
                                </td>
                            </tr>
                        % endfor
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</section>
</%def>